<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" media="screen" type="text/css" href="__THEMES__/style/layout.css" />
		<script type="text/javascript" src="__JS__/jQuery/jquery.js"></script>
		<script type="text/javascript" src="__JS__/jQuery/plugin/troperate.js"></script>
		<script type="text/javascript" src="__JS__/jQuery/plugin/alertbox.js"></script>
		<include file="Public:js_artDialog" />
		<script type="text/javascript">
			$(function(){
				$('#add_role').click(function(){
					art.dialog.loadCall("__URL__/add",{
						title : $(this).val(),
						lock : true
					}, false, function(){
						var ic = $('body',parent.document).find('#add_role_submit');
						ic.submit(function(){
							if ( ic.find('#name').val() == '' ){
								setAlertBox('组名必须！', 2);
								ic.find('#name').addClass('errorInput').focus();
								return false;
							}
							$.post('__URL__/insert',ic.serialize(),function(c){
								setAlertBox(c.info, 2);
								if ( c.status === 0 ){
									return false;
								}else{
									window.location.reload();
								}
							},'json');
							return false;
						});
					});
				});
				//编辑
				$('.edit_role').click(function(){
					var url = $(this).attr('href');
					art.dialog.loadCall(url,{
						title : '编辑用户组',
						lock : true
					}, false, function(){
						var ic = $('body',parent.document).find('#edit_role_submit');
						ic.submit(function(){
							if ( ic.find('#name').val() == '' ){
								setAlertBox('组名必须！', 2);
								ic.find('#name').addClass('errorInput').focus();
								return false;
							}
							$.post('__URL__/update',ic.serialize(),function(c){
								setAlertBox(c.info, 2);
								if ( c.status === 0 ){
									return false;
								}else{
									window.location.reload();
								}
							},'json');
							return false;
						});
					});
					return false;
				});
				//删除
				$('.del_role').click(function(){
					var del_url = $(this).attr('href');
					var _id = $(this).attr('rel');
					$.ajax({
						url : "__URL__/checkDelete/id/" + _id,
						dataType : "json",
						success : function(data){
							if (data.status == 0){
								setAlertBox(data.info, 2);
								return false;
							}else{
								art.dialog.confirm('确认删除操作？',function(){
									window.location.href = del_url;
								},function(){
									//取消操作回调
								});
							}
						},
						cache : false
					});
					return false;
				});
				//用户列表
				$('.role_user_list').click(function(){
					var url = $(this).attr('href');
					art.dialog.loadCall(url,{
						title : $(this).text(),
						width : 750,
						lock : true
					}, false, function(){
						var ic = $('body',parent.document).find('#user_role_submit');
						ic.find('#select_all_user').live('click',function(){
							ic.find('input[name="groupUserId[]"]').attr('checked','checked');
						});
						ic.find('#cancel').live('click',function(){
							ic.find('input[name="groupUserId[]"]').removeAttr('checked');
						});
						ic.submit(function(){
							$.post("__URL__/setUser",ic.serialize(),function(c){
								setAlertBox(c.info, 2);
								if ( c.status === 0 ){
									return false;
								}else{
									window.location.reload();
								}
							},'json');
							return false;
						});
					});
					return false;
				});
				//
				$('.role_action').click(function(){
					art.dialog.open($(this).attr('href'),{
						title : $(this).text(),
						lock : true,
						width : 700,
						height : 400
					});
					return false;
				});
            });
		</script>
	</head>
	<body>
		
		<include file="Public:position" />
			
		<div class="button">
            <input type="button" value="新增角色" class="submit" id="add_role"  />
        </div>
        
        <div class="a_table">
        <table cellspacing="1" width="100%" class="gr_list">
			<tr style="background: #f0f7ff; font-weight: bold;">
				<td width="60" align="center">编号</td>
				<td align="center">组名</td>
				<td width="120" align="center">上级组</td>
				<td width="150" align="center">状态</td>
				<td align="center">描述</td>
				<td width="200" align="center">操作</td>
			</tr>
			{$list}
		</table>
        </div>
        
	</body>
</html>